import { VuexModule, Module, Action, getModule } from 'vuex-module-decorators'
import { getUsers, updateUsers, deleteUsers } from '@/api/users'
import store from '@/store'

export interface IUserState {
  
}

@Module({ dynamic: true, store, name: 'user' })
class User extends VuexModule implements IUserState {

  @Action
  public async GetUsers() {
    return new Promise((r: any, j: any) => {
      getUsers({}).then((value: any) => {
        console.error("Users:", value)
        r(value.data)
      }).catch(ex => {
        console.error(ex);
        j([])
      })
    })
  }

  @Action
  public async updateUsers(data: any) {
    return new Promise((r: any, j: any) => {
      updateUsers(data).then((value: any) => {
        console.error("Users:", value)
        r(value.data)
      }).catch(ex => {
        console.error(ex);
        j([])
      })
    })
  }

  @Action
  public async deleteUsers(staffId: any) {
    return new Promise((r: any, j: any) => {
      deleteUsers({ StaffId: staffId }).then((value: any) => {
        console.error("Users:", value)
        r(value.data)
      }).catch(ex => {
        console.error(ex);
        j([])
      })
    })
  }

}

export const UserModule = getModule(User)
